package com.itlong.cloud.operate.service.impl;

import com.itlong.cloud.POJO.VO.operate.OperateColectionRateVO;
import com.itlong.cloud.operate.dao.IOperateColectionRateDao;
import com.itlong.cloud.operate.service.IOperateColectionRateService;
import com.itlong.cloud.utils.date.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      项目收缴率分析业务处理类
 * </desc>
 *
 * @createDate 2019/06/03
 */
@Service
public class OperateColectionRateServiceImpl implements IOperateColectionRateService{
    @Autowired
    IOperateColectionRateDao iOperateColectionRateDao;

    /**
     * <desc>
     *      列表查询
     * </desc>
     *
     * @param date
     * @param projectId
     * @return
     * @author Jiaqi.X
     * @createDate 2019/06/03
     */
    @Override
    public Map<String,Object> getList(String date, String projectId) {
        Map<String,Object> result =new HashMap<>();
        if(StringUtils.isBlank(date)){
            date = DateUtil.fomatDate(new Date(),"yyyy");
        }
        List<OperateColectionRateVO> list = iOperateColectionRateDao.getList(date,projectId);
        for(OperateColectionRateVO vo : list){
            vo.setColetionRate(new BigDecimal(vo.getPaidMoney()).intValue() == 0 ||
                    new BigDecimal(vo.getTotalMoney()).intValue() == 0 ? "0" :
                    new BigDecimal(vo.getPaidMoney()).divide(
                            new BigDecimal(vo.getTotalMoney()), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).toString());
        }
        result.put("colectionRates",list);
        result.put("defaultYear",date);
        return result;
    }

}
